﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// SubFlow二级流程类
/// </summary>
public class SubFlow
{
    private DBOperation DB;
    private int _parentTypeID;
    private string _subTypeName;
   private int _status;
    private string _brief;
    public int ParentTypeID
    {
        set { _parentTypeID = value; }
        get { return _parentTypeID; }
    }
    public string SubTypeName
    {
        set { _subTypeName = value; }
        get { return _subTypeName; }
    }
 
    public int Status
    {
        set { _status = value; }
        get { return _status; }
    }
    public string Brief
    {
        set { _brief = value; }
        get { return _brief; }
    }
	public SubFlow()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    /// <summary>
    /// 建立一个二级流程对象
    /// </summary>
    /// <param name="parentTypeID">父ID</param>
    /// <param name="subTypeName">流程名称</param>
    /// <param name="brief">相关说明</param>
    public SubFlow(int parentTypeID,string subTypeName,string brief)
    {
        this._parentTypeID = parentTypeID;
        this._subTypeName = subTypeName;
        this._brief = brief;
        this._status = 1;
      
    }
    /// <summary>
    /// 添加一个流程，成功返回真，否则假
    /// </summary>
    /// <returns>成功返回真，否则假</returns>
    public bool AddFlow()
    {
        bool seccess = false;
        string strAddFlow = "insert into FLOWSUBTYPE(PARENTTYPEID,SUBTYPENAME,STATUS,BRIEF) values("
                              +this._parentTypeID+","
                              +"'"+this._subTypeName+"',"
                              +this._status+","
                              +"'"+this._brief+"')";
        DB = new DBOperation();
        seccess = DB.ExcuteSql(strAddFlow);
        return seccess;

    }
    /// <summary>
    /// 修改流程，成功返回真
    /// </summary>
    /// <param name="id">需要修改的流程的ID</param>
    /// <returns>成功返回真、否则假</returns>
    public bool ChangeFlow(int id)
    {
        bool seccess = false;
        string strChangeFlow = "update FLOWSUBTYPE set PARENTTYPEID=" + this.ParentTypeID
                                +",SUBTYPENAME='"+this.SubTypeName+"'"
                                +",BRIEF='"+this.Brief+"'"
                                +" where FLOWSUBTYPEID="+id;
        DB = new DBOperation();
        seccess = DB.ExcuteSql(strChangeFlow);
        return seccess;

    }
    /// <summary>
    /// 删除流程，成功返回真
    /// </summary>
    /// <param name="id">需要删除的流程的ID</param>
    /// <returns>成功返回真，否则假</returns>
    public bool DeleteFlow(int id)
    {
        bool seccess = false;
        string delFlow = "delete FLOWSUBTYPE where FLOWSUBTYPEID="+id;
        DB = new DBOperation();
        seccess= DB.ExcuteSql(delFlow);
        return seccess;
    }
    /// <summary>
    /// 获取系统中已经存在的二级流程
    /// </summary>
    /// <returns>DataSet</returns>
    public DataSet  GetFlow()
    {
        string FindFlow = "select * from FLOWSUBTYPE";
        DB = new DBOperation();
        string tableName = "subFlow";
        DataSet ds = DB.GetDataSet(FindFlow,tableName);
        return ds;
    }
    /// <summary>
    /// 根据流程名称判断该流程是否存在
    /// </summary>
    /// <param name="flowName">流程名称</param>
    /// <returns>存在返回真，否则假</returns>
    public bool FindFlow(string flowName)
    {
        bool isExist = false;
        string findFlow = "select FLOWSUBTYPEID from FLOWSUBTYPE where SUBTYPENAME='"+flowName+"'";
        DB = new DBOperation();
        if (DB.ExcuteScalar(findFlow)!=null)
        {
            isExist = true;

        }
        return isExist;
    }
    /// <summary>
    /// 获取父流程的ID和名称
    /// </summary>
    /// <returns>dateSet</returns>
    public DataSet FindFatherFlow()
    {
        string findFatherFlow = "select FLOWTYPEID,TYPENAME from FLOWTYPE";
        DB=new DBOperation();
        string tableName = "fatherFlow";
       DataSet ds = DB.GetDataSet(findFatherFlow,tableName);
        return ds;
    }
}
